﻿@model  List<FTBS.Models.Entities.ShowTime>

@{
    var listShowTimeFuture = new List<FTBS.Models.Entities.ShowTime>();
    var listShowTimeActive = new List<FTBS.Models.Entities.ShowTime>();
    var showTimeSelected = (int)ViewBag.ShowTimeIdSelected;
}

@if (Model != null)
{
    foreach (var item in Model)
    {
        if (item.IsActive == false)
        {
            listShowTimeFuture.Add(item);
        }
        else
        {
            listShowTimeActive.Add(item);
        }
    }

    if (listShowTimeActive.Count() > 0)
    {
        <p style="color:red">Giờ chiếu đang áp dụng chiếu</p>
        foreach (var item in listShowTimeActive)
        {
            var hour = string.Empty;
            var minutes = string.Empty;
            if (item.Time.Hours < 10)
            {
                hour = "0" + item.Time.Hours.ToString();
            }
            else
            {
                hour = item.Time.Hours.ToString();
            }
            if (item.Time.Minutes < 10)
            {
                minutes = "0" + item.Time.Minutes.ToString();
            }
            else
            {
                minutes = item.Time.Minutes.ToString();
            }
            var timeToShow = hour + ":" + minutes;
        
        @Html.RadioButtonFor(showtime => item.ShowTimeId, item.ShowTimeId, new { @onclick = "chooseRadio()" }) @:Ngày: @item.Date.ToString("dd/MM/yyyy")  <br /> &nbsp;&nbsp;&nbsp; Giờ: @timeToShow <br />
        }
    }

    if (listShowTimeFuture.Count() > 0)
    {
        <br /><p style="color:red">Giờ chiếu chưa áp dụng chiếu</p>
        foreach (var item in listShowTimeFuture)
        {
            var hour = string.Empty;
            var minutes = string.Empty;
            if (item.Time.Hours < 10)
            {
                hour = "0" + item.Time.Hours.ToString();
            }
            else
            {
                hour = item.Time.Hours.ToString();
            }
            if (item.Time.Minutes < 10)
            {
                minutes = "0" + item.Time.Minutes.ToString();
            }
            else
            {
                minutes = item.Time.Minutes.ToString();
            }
            var timeToShow = hour + ":" + minutes;
            @Html.RadioButtonFor(showtime => item.ShowTimeId, item.ShowTimeId, new { @onclick = "chooseRadio()" }) @:Ngày: @item.Date.ToString("dd/MM/yyyy")  <br /> &nbsp;&nbsp;&nbsp; Giờ: @timeToShow <br />
        }
    }
}
else
{
    <p style="color:red">Xin hãy chọn rạp chiếu để hiển thị giờ chiếu!</p>
}

<script type="text/javascript">
    $(document).ready(function () {
        var showtimeSelect = document.getElementById("showTimeIdSelected").value;
        var radios = document.getElementsByName("item.ShowTimeId");
        for (i = 0; i < radios.length; i++) {
            if (radios[i].value == showtimeSelect) {
                radios[i].checked = true;
            }
        }
    });
    $("input:radio").attr("checked", false);
    $(":radio").click(function () {
        var Selectedvalue = $(this).val();
        document.getElementById("showTimeIdSelected").value = Selectedvalue
    });
</script>